import moment from "moment";

// 处理状态
export const PROCESS_STATUS = {
    0: {'code': 0, 'text': '待处理'}, 1: {'code': 1, 'text': '已处理'},
};

// 使用状态
export const USE_STATUS = {
    0: {'code': 0, 'text': '已失效'}, 1: {'code': 1, 'text': '使用中'},
};

// 时间格式化
export function formatTimestamp(timestamp = null, format = 'YYYY-MM-DD HH:mm:ss') {
    if (!timestamp) {
        return null;
    }
    let date = new Date(timestamp);
    /**
     * timezone offset = 0 时为UTC 时间
     * 添加 8 小时替代 GMT 时间
     */
    if (date.getTimezoneOffset() === 0) {
        date.setUTCHours(date.getUTCHours() + 8);
    }
    return moment(date.getTime()).format(format);
}

export const SHORTCUTS = [
    {
        text: '最近一天',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24)
            return [start, end];
        }
    },
    {
        text: '最近一周',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            return [start, end];
        }
    },
    {
        text: '最近一个月',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            return [start, end];
        }
    },
    {
        text: '最近三个月',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            return [start, end];
        }
    }
]